package config

import (
	"github.com/go-kit/kit/log"
	"github.com/go-kit/kit/log/level"
	"gopkg.in/yaml.v2"
	"io/ioutil"
)

type config struct {
	ServicePrefixMapping map[string]string `yaml:"servicePrefixMapping"`
}

var Cfg = new(config)

func Init(logger log.Logger) {
	var path = "config.yml"
	err := YamlToStruct(path, Cfg)
	if err != nil {
		level.Error(logger).Log("msg", "Fatal error config file", "err", err)
	}
}

func YamlToStruct(file string, out interface{}) (err error) {
	var buf []byte
	buf, err = ioutil.ReadFile(file)

	if err != nil {
		return
	}
	err = yaml.Unmarshal(buf, out)
	return
}
